<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<!DOCTYPE html>
<html>
<head>
    <title>企业信息完善</title>
    <%@include file="/WEB-INF/pages/common/taglib.jsp" %>
    <%@include file="/WEB-INF/pages/common/common.jsp" %>
</head>
<body>
<div>
    <div class="header_line">
        当前位置：企业信息管理<span>&gt;</span><strong>子账号管理</strong>
    </div>
    <div class="mt10"></div>
    <div class="mt10"></div>
    <form id="form_search">
        <table class="table_search">
            <tbody>
            <tr>
                <td class="width30p"><label>用户名:</label></td>
                <td class="width70p"><input type="text" name="username"></td>
                <td class="width30p"><label>邮箱:</label></td>
                <td class="width70p"><input type="text" name="email"></td>
            </tr>
            </tbody>
        </table>
    </form> <br/>
    <div class="searchButton" style="align:center">
        <div class="searchButton">
            <input type="button" value="查 询"
                   onclick="javascript:$('#corptable').jqGrid({postData: form2json('form_search')}).trigger('reloadGrid');"/>
            <input type="button" value="新增" onclick="javascript:addChildUser()"/>
            <input type="button" value="重 置" onclick="javascript:document.forms[0].reset();"/>
        </div>
    </div>
    </br/>
    <div class='responsive-table'>
        <table id="corptable">
        </table>
        <div id="jqGridPager">
        </div>
    </div>
</div>
<script>
    function isNotNull(param) {
        if ($.trim(param) != "" && param != null) {
            return true;
        } else {
            return false;
        }
    }
    //将表单数据转为json
    function form2Json(id) {
        var arr = $("#" + id).serializeArray();
        var jsonStr = "";
        var json = "";
        for (var i = 0; i < arr.length; i++) {
            if (isNotNull(arr[i].value)) {
                jsonStr += '"' + arr[i].name + '":"' + arr[i].value + '",'
            }
        }
        if (isNotNull(jsonStr)) {
            jsonStr = jsonStr.substring(0, (jsonStr.length - 1));
            jsonStr = "{" + jsonStr + "}";
            json = JSON.parse(jsonStr);
        }
        return json;
    }
    function addChildUser() {
        layer.open({
            type: 2,
            title: '新增子账号',
            shadeClose: true,
            shade: 0.8,
            area: ['700px', '280px'],
            content: '${basePath}/enterprise/addUser?userId=${parentId}',
            end: function () {
                $("#corptable").jqGrid().trigger("reloadGrid");
            }
        })
    }
    $(function () {
        $("#corptable").jqGrid({
            datatype: "json",
            url: "${basePath}/enterprise/pageChildUser?userId=${parentId}",
            postData: {}, //发送数据
            colNames: ['用户名', '邮箱', '手机号码'],
            colModel: [
                {name: 'username', index: 'username'},
                {name: 'email', index: 'email'},
                {name: 'mobilePhoneNumber', index: 'mobilePhoneNumber'}],
            autowidth: true,
            height: 'auto',
            shrinkToFit: false,
            forceFit: true,
            autoScroll: false,
            rowNum: 10, //每页显示记录数
            rowList: [10, 20, 100], //可调整每页显示的记录数
            rownumbers: true,
            rownumWidth: 35,
            multiselect: false, //是否支持多选
            viewrecords: true, //是否显示行数
            pager: "#jqGridPager", //分页工具栏
            altRows: true,
            altclass: 'someClass',
            sortable: false,
            loadComplete: function () {
                var rowNum = $(this).jqGrid('getGridParam', 'records');
                if (rowNum <= 0) {
                    if ($(this).parent().children('.norecords').length == 0)
                        $(this).parent().append("<div class=\"norecords\">暂无数据！</div>");
                    $(this).parent().children('.norecords').show();
                } else {//如果存在记录，则隐藏提示信息。
                    $(this).parent().children('.norecords').hide();
                }
                $("#corptable").setGridWidth($(window).width() * 0.98);
                $(".ui-jqgrid tr.ui-row-ltr td").css('text-align', 'center');
            }
        });

    });

</script>
</body>
</html>
